package com.pctc.config;



import com.pctc.interceptor.ResourcesInterceptor;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.*;




@Configuration
//等同于<context:component-scan base-package="com.pctc.controller"/>
@ComponentScan({"com.pctc.controller"})

//等同于<mvc:annotation-driven/>
@EnableWebMvc
public class SpringMvcConfig  implements WebMvcConfigurer {



    @Bean
    public ResourcesInterceptor resourcesInterceptor(){
        return new ResourcesInterceptor();
    }
    /*
     * 在注册的拦截器类中添加自定义拦截器
     * addPathPatterns()方法设置拦截的路径
     * excludePathPatterns()方法设置不拦截的路径
     */

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor( resourcesInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**","/js/**","/img/**");
    }

    /*
     *开启对静态资源的访问
     * 类似在Spring MVC的配置文件中设置<mvc:default-servlet-handler/>元素
     */

    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }



   /*  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/admin/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>*/

    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/views/",".jsp");
    }

}




